<template>
  <div id="app" ref="app">
    <router-view/>
  </div>
</template>
<script>
  export default {
    methods: {
      handleNetworkError (element, type, handler) {
        if (element.addEventListener) {
          element.addEventListener(type, handler, false)
        } else if (element.attachEvent) {
          element.attachEvent('on' + type, handler)
        } else {
          element['on' + type] = handler
        }
      }
    },
    created () {
      // 监听网络是否良好
      var _this = this
      this.handleNetworkError(window, 'offline', function () {
        _this.$router.push({
          path: '/networkerror'
        })
        console.log('网络断开')
      })

      this.handleNetworkError(window, 'online', function () {
        console.log('网络重新连接')
        window.history.go(-1)
      })
    },
    mounted () {
      this.$refs.app.style.minHeight = window.innerHeight + 'px'
    }
  }
</script>

<style>
  #app {
    font-family: 'Avenir', Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    background-color: #f7f7f7;
    overflow: hidden;
  }
</style>
